package com.app.util.limiter;

import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

/**
 * 频率限制名称对象
 * 
 * @author yao
 */
public class LimitNames {

	private Object lock = new Object();
	private Map<String, NameItem> names = new HashMap<String, NameItem>();

	/**
	 * 增加一个频率项
	 * 
	 * @param name
	 * @param max
	 */
	public void addName(String name) {
		synchronized (lock) {
			names.put(name, new NameItem(name, names.size()));
		} 
	}

	public Collection<NameItem> getAllNameItem() {
		return Collections.unmodifiableCollection(names.values());
	}

	public NameItem getNameItem(String name) {
		return names.get(name);
	}

	public int size() {
		return names.size();
	}

	public class NameItem {

		private String name;
		private int index;

		private NameItem(String name, int index) {
			this.name = name;
			this.index = index;
		}

		public String getName() {
			return name;
		}

		public int getIndex() {
			return index;
		}

	}
}
